package com.gexiaobao.pigeon.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.OrderTakingResponseList
import com.gexiaobao.pigeon.databinding.ItemOrderSquareBinding
import java.text.DecimalFormat

/**
 * @Author      : hxw
 * @Date        : 2024/6/24 14:23
 * @Describe    :
 */
class AdapterOrderSquare(data: ArrayList<OrderTakingResponseList>) :
    BaseQuickAdapter<OrderTakingResponseList, DataBindBaseViewHolder>(R.layout.item_order_square, data) {
    override fun convert(holder: DataBindBaseViewHolder, item: OrderTakingResponseList) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemOrderSquareBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val result = item.distance
        if (result != 0.0) {
            val distance = result / 1000
            val df = DecimalFormat("#0.00")
            holder.setText(R.id.tvDistance, "距离:  " + df.format(distance).toString() + "公里")
        }

        var btnStateContent = ""
        var orderStateContent = ""
        var btnStateBackground = 0
        var orderStateBackground = 0
        when (item.status) {//1创建2发布3已接单4已接鸽5已完成
            4 -> {
                orderStateContent = context.getString(R.string.Received_pigeon)
                btnStateContent = context.getString(R.string.detail)//"详情"
                btnStateBackground = R.drawable.shape_oval30_003366
                orderStateBackground = R.drawable.round_bg25_003366_half
            }

            3 -> {
                orderStateContent = context.getString(R.string.Non_trading_order_has_been_received)//"已接单"
                btnStateContent = context.getString(R.string.navigation)//"导航"
                btnStateBackground = R.drawable.shape_oval30_003366
                orderStateBackground = R.drawable.round_bg25_003366_half
            }

            2 -> {
                orderStateContent = context.getString(R.string.Favorite_Single)//"待接单"
                btnStateContent = context.getString(R.string.order_receiving)//"接单"
                btnStateBackground = R.drawable.shape_oval_red30
                orderStateBackground = R.drawable.round_bg8_red_half_top_bottom
            }

            else -> {
                orderStateContent = context.getString(R.string.market_shop_order_list_for_fragment_layout_activity_my_order_tab_complete)//"已完成"
                btnStateContent = context.getString(R.string.detail)//"详情"
                btnStateBackground = R.drawable.shape_oval30_003366
                orderStateBackground = R.drawable.round_bg25_gray_half
            }
        }
        holder.setText(R.id.tvOrderState, orderStateContent)
        holder.setText(R.id.tvReceiptOrder, btnStateContent)
        holder.setBackgroundResource(R.id.tvReceiptOrder, btnStateBackground)
        holder.setBackgroundResource(R.id.tvOrderState, orderStateBackground)
    }
}